package com.nulldev.util.uri.server.v2.demo;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.HashMap;

import com.nulldev.util.java.DataSet;
import com.nulldev.util.java.swing.font.FontManager;
import com.nulldev.util.net.IPUtil;
import com.nulldev.util.uri.server.RequestType;
import com.nulldev.util.uri.server.v2.HttpPage2;
import com.nulldev.util.uri.server.v2.HttpServer2;

public class HttpServer2Demo {

	public static void main(String[] args) throws Exception {
		final HttpServer2 http = new HttpServer2(IPUtil.nextFreePortIterated(4900, 8081), false);
		http.putSetting(http.KEY_WEB_SERVER_NAME, "HttpServer2 Demo");
		http.addPage(new HttpPage2("/") {
			
			@Override
			public DataSet<Integer, InputStream> request(RequestType type, String url, HashMap<String, String> headers,
					byte[] extraData, final String ip) {
				return new DataSet<Integer, InputStream>(200, new ByteArrayInputStream(toBytes("It works!")));
			}
		});
		http.setMaintenance(true);
		FontManager.__print_fonts();
	}

}
